package com.mvc4g.example.client.customer.views;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Event;
import com.mvc4g.example.client.customer.CustomerBean;

public class DisplayCustomerView extends AbstractCustomerView {

	private Label lastName = null;
	private Label firstName = null;
	private CustomerBean customer = null;

	protected void finishCreation() {
		lastName = new Label();
		firstName = new Label();
		grid.setWidget(0, 1, lastName);
		grid.setWidget(1, 1, firstName);
	}

	public void init(CustomerBean customer) {
		this.customer = customer;
		lastName.setText(customer.getLastName());
		firstName.setText(customer.getFirstName());
	}

	protected Widget getLastName() {
		if (lastName == null) {
			lastName = new Label();
		}
		return lastName;
	}

	protected Widget getFirstName() {
		if (firstName == null) {
			firstName = new Label();
		}
		return firstName;
	}

	protected String getButtonText() {
		return "Copy";
	}

	protected void buttonAction() {
		controller.handleEvent(new Event(COPY_CUSTOMER, customer));
	}

}
